package com.yxt.ui;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.yxt.common.sys.CommConstant;
import com.yxt.common.sys.CommUtil;
import com.yxt.common.ui.ActivityStackControlUtil;
import com.yxt.common.ui.StationOverlay;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;

public class SoilStationMapActivity extends MapActivity {
	private MapView mapView;
	private static final int MODEL_SATELITE = Menu.FIRST+1;
	private static final int MODEL_STREET = Menu.FIRST+2;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏
		setContentView(R.layout.salt_map); // 软件activity的布局
		ActivityStackControlUtil.add(this);
		initComponent();		
	}
	
	private void initComponent() {
		Button btnBackHome = (Button) findViewById(R.id.btnBackHome);
		btnBackHome.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				Intent intent = new Intent();
				intent.setClass(getApplicationContext(), MainActivity.class);
				startActivity(intent);
			}
		});
		mapView = (MapView) findViewById(R.id.map_view);
		
		Intent intent = getIntent();
		String code = intent.getStringExtra("code");
		String name = intent.getStringExtra("name");
		GeoPoint point = new GeoPoint(CommUtil.getGisDegree(intent.getStringExtra("wd")), CommUtil.getGisDegree(intent.getStringExtra("jd")));
		StationOverlay overlay = new StationOverlay(getApplicationContext(),point,"测站名称："+name + "\n测站编号：" + code);
		mapView.getOverlays().add(overlay);
		MapController mc = mapView.getController();
		mc.setZoom(CommConstant.Config.DEFAULT_ZOOM);
		mc.animateTo(point);
	}

	protected boolean isRouteDisplayed() {
		return false;
	}
	
	/**
	 * 创建底部菜单
	 * */
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		menu.add(0, MODEL_SATELITE, 3, R.string.model_satelite);
		menu.add(0, MODEL_STREET, 4, R.string.model_street);
		return super.onCreateOptionsMenu(menu);
	}
	
	/**
	 * 点击底部菜单项时的处理
	 */
	public boolean onOptionsItemSelected(MenuItem item) {	
		switch (item.getItemId()) {
			case MODEL_SATELITE:
				mapView.setSatellite(true);
				mapView.setStreetView(false);
				return true;
			case MODEL_STREET:
				mapView.setStreetView(true);
				mapView.setSatellite(false);		
				return true;
		}
		return super.onOptionsItemSelected(item);
	}
	
	protected void onDestroy() {     
        super.onDestroy();
        ActivityStackControlUtil.remove(this);
	}
}